from django.db import models

from device.base import Constant
from device.user import User


class Device(models.Model):
    class Meta:
        db_table = 'statistic_device'
        verbose_name = '设备记录'
        verbose_name_plural = '设备记录'
        unique_together = ("device_id", "platform", "idfv")

    device_id = models.CharField(max_length=100, verbose_name=u'设备ID')
    platform = models.CharField(choices=Constant.PLATFORM_CHOICES, default='Android', max_length=20,
                                verbose_name=u'设备类型')
    version = models.CharField(verbose_name=u'APP版本', null=True, max_length=10)
    os_version = models.CharField(verbose_name=u'系统版本', null=True, max_length=20)
    model = models.CharField(verbose_name=u'Model', null=True, max_length=40)
    # Android Only
    screen = models.CharField(verbose_name=u'屏幕分辨率', null=True, max_length=40)
    channel = models.CharField(verbose_name=u'渠道', null=True, max_length=40)

    # User Info
    user = models.ManyToManyField(User, related_name="devices")

    # time
    created_time = models.DateTimeField(auto_now_add=True, verbose_name="创建时间")
    last_activity = models.DateTimeField(auto_now=True, verbose_name=u'最后活跃时间')

    # add by chengliang @2016-09-23, for iOS IDFV
    idfv = models.CharField(max_length=100, verbose_name=u'iOS设备的idfv或Android设备的mac', null=False, default="")